package com.hmall.search.controller;

import com.hmall.api.dto.ItemDTO;
import com.hmall.item.domain.query.ItemPageQuery;
import com.hmall.common.domain.PageDTO;
import com.hmall.search.service.ISearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

/**
 * @author 李建舜
 * @version 1.0
 * @date 2025/3/15 15:12
 * @description
 */
@Slf4j
@Api(tags = "搜索相关接口")
@RestController
@RequestMapping("/item/search")
@RequiredArgsConstructor
public class ItemSearchController {
    private final ISearchService searchService;

    @ApiOperation("通过es根据id查询商品")
    @GetMapping("{id}")
    public ItemDTO queryItemById(@PathVariable("id") Long id) throws Exception {
        return searchService.queryItemById(id);
    }

    @ApiOperation("搜索商品")
    @GetMapping("/list")
    public PageDTO<ItemDTO> itemSearch(ItemPageQuery query) throws IOException {
        return searchService.search(query);
    }

    @ApiOperation("搜索商品分类")
    @PostMapping("/filters")
    public Map filters(@RequestBody ItemPageQuery query) throws IOException {
        return searchService.searchFilters(query);
    }
}
